package cn.topcodes.tcsf.admin.commons.domain;

import cn.topcode.unicorn.utils.I18n;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;

/**
 * 实体公共抽象
 * 列出了实体必须有的四个属性：id、createdTime、updatedTime、dataState
 * @author Unicorn
 *
 */
@Data
public abstract class IdEntity implements Idable, Serializable {

	private static final long serialVersionUID = 1L;


	/**
	 * 字段名称常量 - id，唯一标识
	 */
	public static final String FIELD_ID = "id";

	/**
	 * 字段名称常量 - id，创建时间
	 */
	public static final String FIELD_CREATED_TIME = "createdTime";

	/**
	 * 字段名称常量 - id，更新时间
	 */
	public static final String FIELD_UPDATED_TIME = "updatedTime";

	/**
	 * 字段名称常量 - id，数据状态
	 */
	public static final String FIELD_DATA_STATE = "dataState";



	/**
	 * 数据状态 - 启用
	 */
	public static final String DATA_STATE_ENABLE = "Enable";

	/**
	 * 数据状态 - 禁用
	 */
	public static final String DATA_STATE_DISABLE = "Disable";

	/**
	 * 数据状态 - 删除
	 */
	public static final String DATA_STATE_DELETE = "Delete";

	/**
	 * 主键
	 */
	@Id
	private Long id;

	/**
	 * 创建时间
	 */
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date createdTime;

	/**
	 * 更新时间
	 */
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date updatedTime;

	/**
	 * 数据状态
	 */
	@I18n(module = "commons")
	private String dataState;

	/**
	 * 克隆此实体对象，TODO 可能存在浅克隆问题
	 * @return
	 */
	@Override
	public Object clone() {
		try {
			IdEntity idEntity = this.getClass().newInstance();
			BeanUtils.copyProperties(this, idEntity);
			return idEntity;
		} catch (Exception e) {
			throw new IllegalStateException(this.getClass().getName() + " clone unsupport!");
		}
	}
}
